//
//  HDCFDdmmCell.m
//  HaoDeCaiFu
//
//  Created by 郑开宏 on 2017/11/2.
//  Copyright © 2017年 郑开宏. All rights reserved.
//

#import "HDCFDdmmCell.h"

@interface HDCFDdmmCell ()


@end

@implementation HDCFDdmmCell

- (void)setIndex:(NSInteger)index{
    _index = index;
}

- (void)setDataDict:(NSDictionary *)dataDict{
    _dataDict = dataDict;
    if (_fromID == 1) {
        self.fundName.text = dataDict[@"subShortName"];
        self.fundCode.text = dataDict[@"productCode"];
        NSString *earnT = dataDict[@"revenueMode"];
        if ([earnT isEqualToString:@"float"]) {
            self.earnTypeText.text = @"浮动收益";
        }else{
            self.earnTypeText.text = @"固定收益";
        }
        
        if ([dataDict[@"nav"] isKindOfClass:[NSNull class]]) {
            self.wanEarn.text = @"--";
        }else{
            NSNumber *nav = dataDict[@"nav"];
            self.wanEarn.text = [NSString stringWithFormat:@"%.4f", nav.doubleValue];
        }
        
        NSString *status = dataDict[@"status"];
        if ([status isEqualToString:@"active"]) {
            NSNumber *minInitialBuyAmount = dataDict[@"minInitialBuyAmount"];
            self.startMoney.text = [NSString stringWithFormat:@"%@元", minInitialBuyAmount.stringValue ];
        }else if ([status isEqualToString:@"ipo"]){
            NSNumber *minInitialIpoAmount = dataDict[@"minInitialIpoAmount"];
            self.startMoney.text = [NSString stringWithFormat:@"%@元", minInitialIpoAmount.stringValue ];
        }else if ([status isEqualToString:@"inActive"]){
            self.startMoney.text = @"处于封闭期";
        }else if ([status isEqualToString:@"closure"]){
            self.startMoney.text = @"已清盘";
        }
        
        NSString *isBuyEnable = dataDict[@"isBuyEnable"];
        if ([isBuyEnable isEqualToString:@"Y"]) {
            [self.buyBtn setBackgroundColor:ZKcolor(184, 27, 36)];
            [self.buyBtn setTitle:@"立即购买" forState:UIControlStateNormal];
            
        }else{
            [self.buyBtn setBackgroundColor:[UIColor lightGrayColor]];
            [self.buyBtn setTitle:@"已售罄" forState:UIControlStateNormal];
        }
    }
    else if (_fromID == 2)
    {
        self.fundName.text = dataDict[@"FundName"];
        self.fundCode.text = dataDict[@"FundCode"];
//        NSString * fundTypeStr;
//        if ([dataDict[@"FundType"] isKindOfClass:[NSNull class]]) {
//            fundTypeStr = @"";
//        }
//        else
//        {
//            fundTypeStr = [NSString stringWithFormat:@"%@",dataDict[@"FundType"]];
//        }
//        self.earnTypeText.text = fundTypeStr;
        
        self.earnTypeText.text = @"浮动收益";
        
        NSString *minInitialBuyAmount = dataDict[@"MinInitialIpoAmount"];
        if ([dataDict[@"MinInitialIpoAmount"] isKindOfClass:[NSNull class]]) {
            minInitialBuyAmount = @"";
        }
        self.startMoney.text = [NSString stringWithFormat:@"%@", minInitialBuyAmount];
//        NSString *status = [dataDict[@"State"] stringValue];
//        if ([status isEqualToString:@"active"]) {
//            NSNumber *minInitialBuyAmount = dataDict[@"minInitialBuyAmount"];
//            self.startMoney.text = [NSString stringWithFormat:@"%@元", minInitialBuyAmount.stringValue ];
//        }else if ([status isEqualToString:@"ipo"]){
//            NSNumber *minInitialIpoAmount = dataDict[@"minInitialIpoAmount"];
//            self.startMoney.text = [NSString stringWithFormat:@"%@元", minInitialIpoAmount.stringValue ];
//        }else if ([status isEqualToString:@"inActive"]){
//            self.startMoney.text = @"处于封闭期";
//        }else if ([status isEqualToString:@"closure"]){
//            self.startMoney.text = @"已清盘";
//        }
        
        NSString *isBuyEnable = [dataDict[@"State"] stringValue];
        if ([isBuyEnable isEqualToString:@"1"]) {
            [self.buyBtn setBackgroundColor:ZKcolor(184, 27, 36)];
            [self.buyBtn setTitle:@"立即预约" forState:UIControlStateNormal];
            
        }else if([isBuyEnable isEqualToString:@"2"])
        {
            [self.buyBtn setBackgroundColor:[UIColor lightGrayColor]];
            [self.buyBtn setTitle:@"已售罄" forState:UIControlStateNormal];
            //self.buyBtn.userInteractionEnabled = NO;
        }
        else if([isBuyEnable isEqualToString:@"0"])
        {
            [self.buyBtn setBackgroundColor:[UIColor lightGrayColor]];
            [self.buyBtn setTitle:@"即将开售" forState:UIControlStateNormal];
            //self.buyBtn.userInteractionEnabled = NO;
        }
        
        self.wanEarn.hidden = YES;
        self.valueLabel.hidden = YES;
    }
}

+(instancetype)HDCFDdmmCell{
    return [[NSBundle mainBundle] loadNibNamed:@"HDCFDdmmCell" owner:nil options:nil].firstObject;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    self.buyBtn.layer.cornerRadius = 2.0;
    self.backView.layer.shadowColor = ZKcolor(220, 220, 220).CGColor;//shadowColor阴影颜色
    self.backView.layer.shadowOffset = CGSizeMake(0,0);//shadowOffset阴影偏移,x向右偏移4，y向下偏移4，默认(0, -3),这个跟shadowRadius配合使用
    self.backView.layer.shadowOpacity = 0.5;//阴影透明度，默认0
    self.backView.layer.shadowRadius = 4;//阴影半径，默认3
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}
- (IBAction)buyBtnClick:(UIButton *)sender {
    if ([self.delegate respondsToSelector:@selector(hdcfDdmmcell:withIndex:)]) {
        [self.delegate hdcfDdmmcell:self withIndex:_index];
    }
}

@end
